#include "./../inc/main.h"

// 延时函数
void cross_sleep(unsigned int milliseconds)
{
#ifdef _WIN32
    Sleep(milliseconds);
#else
    usleep(milliseconds * 1000); // Linux使用微秒单位，需要乘以1000
#endif
}

void clearScreen()
{
#ifdef _WIN32
    system("cls");
#else
    system("clear");
#endif
}

void waitForAnyKey()
{
    printf("按任意键继续...");
    fflush(stdout);

    getchar();

    int c;
    clearChar();
}

void clearChar()
{
    int c;
    while ((c = getchar()) != '\n' && c != EOF)
        ;
}

void enableANSISupport()
{
#ifdef _WIN32
    // 启用Windows 10的ANSI转义序列支持
    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    DWORD dwMode = 0;
    GetConsoleMode(hOut, &dwMode);
    dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
    SetConsoleMode(hOut, dwMode);
#endif
}